//
//  AXZxktJpktVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/2.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXZxktJpktVC.h"
#import "Header.h"
#import "ZXCategories.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "AXZxktJpktCell.h"
#import "AXZxktJpktModel.h"
#import "TFDropDownMenu.h"
#import "UIViewController+HBD.h"
#import "LLSearchViewController.h"


//#define ZX_WEAK_CELL(cell) __weak typeof(cell) weakCell = cell;

@interface AXZxktJpktVC ()<UITableViewDelegate,UITableViewDataSource,TFDropDownMenuViewDelegate>




@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<AXZxktJpktModel *>  *modelsArray;

@end

@implementation AXZxktJpktVC




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    //self.view.backgroundColor = [UIColor whiteColor];
    /** 导航条白色 */
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
}

- (void)creatView {
    
  
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    //注册cell
    [self.tableView registerClass:[AXZxktJpktCell class] forCellReuseIdentifier:[AXZxktJpktCell reuseID]];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIButton *searchButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-140, 30)];
    searchButton.backgroundColor = [UIColor whiteColor];
    searchButton.titleLabel.font = FONT_TWELVE;
    [searchButton addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
    [searchButton setTitleColor:COLOR_Gray forState:UIControlStateNormal];
    [searchButton setTitle:@"精品课堂" forState:UIControlStateNormal];
    searchButton.cornerRadius = 15;
    [searchButton setImage:[UIImage imageNamed:@"ss"] forState:UIControlStateNormal];
    self.navigationItem.titleView = searchButton;
    self.hbd_barShadowHidden = YES;
    
    
}


#pragma mark - 搜索

/** 搜索 */
- (void)search:(UIButton *)btu {
    
    LLSearchViewController *vc = [[LLSearchViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - tableViewDelegate & tableViewDatasorce


//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
  
    NSMutableArray *array1 = [NSMutableArray arrayWithObjects:@"综合", @"面积最小", @"价格最高", @"价格最低", nil];
    NSMutableArray *array2 = [NSMutableArray arrayWithObjects:@"全部", @"美食", @"影院", @"自助餐", @"景区", @"汽车", @"网吧", @"游戏", nil];
    NSMutableArray *array3 = [NSMutableArray arrayWithObjects:@"筛选", @"从小到大", @"从高到低", @"从低到高", @"从右到左", @"从左到右", @"从前到后", @"从后到前", nil];

    NSMutableArray *data1 = [NSMutableArray arrayWithObjects:array1, array2, array3, nil];
    NSMutableArray *data2 = [NSMutableArray arrayWithObjects:@[], @[], @[], @[], nil];
    TFDropDownMenuView *menu = [[TFDropDownMenuView alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 40) firstArray:data1 secondArray:data2];
    menu.delegate = self;
    menu.cellSelectBackgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    menu.ratioLeftToScreen = 0.35;
    menu.tableViewHeight = UIScreen.mainScreen.bounds.size.height-NAVBAR_HEIGHT-40;
    /*风格*/
    menu.menuStyleArray = [NSMutableArray arrayWithObjects:[NSNumber numberWithInteger:TFDropDownMenuStyleTableView], [NSNumber numberWithInteger:TFDropDownMenuStyleTableView], [NSNumber numberWithInteger:TFDropDownMenuStyleTableView], [NSNumber numberWithInteger:TFDropDownMenuStyleTableView], nil];
    
    
    
    return menu;
    
    
}
/** 分区的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return 44;
    
}

#pragma mark DropDownMenuView Delegate

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)menuView:(TFDropDownMenuView *)menu selectIndex:(TFIndexPatch *)index {
    NSLog(@"index: %@", index);
}

- (void)menuView:(TFDropDownMenuView *)menu tfColumn:(NSInteger)column {
    NSLog(@"column: %ld", column);
}


/** cell 的点击方法 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
  
    
}

//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return 10;
}

/** cell的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXZxktJpktCell class] contentViewWidth:SCREEN_WIDTH];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

        
        AXZxktJpktCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXZxktJpktCell reuseID] forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        return cell;
  
    
    
}



@end



